#include "betanode.h"
#include "math.h"

BetaNode::BetaNode(double val):
        Node(val)
{
    alphaNode = -1;
    betaNode  = -1;
}

BetaNode::BetaNode(QString lbl, double val, double sd, Node * alphaNode, Node * betaNode, bool observed):
        Node(lbl, val, sd, observed)
{
    setAlphaNode(alphaNode);
    setBetaNode(betaNode);
}

bool BetaNode::inRange(double v)
{
    return 0.0 <= v && v <= 1.0;
}

void BetaNode::setAlphaNode(Node * node)
{
    alphaNode = addParentNode(node);
}

void BetaNode::setBetaNode(Node * node)
{
    betaNode = addParentNode(node);
}

double BetaNode::computeLogLikelihood()
{   
    double aVal = parents->at(alphaNode)->getValue();
           //aVal = aVal < 0.0 ? 0.0 : aVal;
           //aVal = aVal > 1.0 ? 1.0 : aVal;
    double bVal = parents->at(betaNode)->getValue();

    double val = gsl_ran_beta_pdf(this->getValue(),
                                  aVal,
                                  bVal);
    return VALID_LOG(val);
}
